import sys

from PyQt5.QtCore import QSize, Qt
from PyQt5.QtWidgets import QApplication, QMainWindow, QToolBar, QAction
from PyQt5.QtGui import QColor, QIcon
import qtawesome as qta


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        # 创建一个工具栏
        self.toolbar = QToolBar("My Toolbar")

        # 创建一些动作
        icon_new = qta.icon('ei.file-new-alt', color=QColor('#1296db'))
        new_action = QAction(icon_new, "New", self)
        new_action.triggered.connect(self.new_file)

        icon_open = qta.icon('ei.folder-open', color=QColor('#1296db'))
        open_action = QAction(icon_open, "Open", self)
        open_action.triggered.connect(self.open_file)

        icon_save = qta.icon('fa5s.save', color=QColor('#1296db'))
        save_action = QAction(icon_save, "Save", self)
        save_action.triggered.connect(self.save_file)

        fa5_icon = qta.icon('mdi6.content-cut', color=QColor('#1296db'))
        cut_action = QAction(fa5_icon, "剪切", self)
        cut_action.triggered.connect(self.cut_file)

        # 将动作添加到工具栏
        self.toolbar.addAction(new_action)
        self.toolbar.addAction(open_action)
        self.toolbar.addAction(save_action)
        self.toolbar.addAction(cut_action)

        # 将工具栏添加到主窗口
        self.addToolBar(self.toolbar)
        self.toolbar.setIconSize(QSize(23, 23))
        self.toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        self.toolbar2 = QToolBar("sxt Tool")
        icon_edit = qta.icon('ei.edit', color=QColor('#1296db'))
        update_action = QAction(icon_edit, "编辑", self)
        update_action.triggered.connect(self.update_file)

        self.toolbar2.addAction(update_action)
        self.addToolBar(self.toolbar2)
        self.toolbar2.setIconSize(QSize(23, 23))
        # 设置主窗口的大小和标题
        self.setGeometry(200, 200, 1400, 800)
        self.setWindowTitle("QToolBar Example")

    def new_file(self):
        print("New file action triggered!")

    def open_file(self):
        print("Open file action triggered!")

    def save_file(self):
        print("Save file action triggered!")

    def cut_file(self):
        print("Cut file action triggered!")

    def update_file(self):
        print("Update file action triggered!")


if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainWin = MainWindow()
    mainWin.show()
    sys.exit(app.exec_())
